<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>客户流失暂缓管理</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/jquery-easyui-1.8.6/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/jquery-easyui-1.8.6/themes/icon.css">
    <script type="text/javascript" src="${pageContext.request.contextPath}/jquery-easyui-1.8.6/jquery.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/jquery-easyui-1.8.6/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/jquery-easyui-1.8.6/jquery.edatagrid.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/jquery-easyui-1.8.6/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/common.js"></script>
</head>
<body>

<div id="p" class="easyui-panel" title="客户流失基本信息" style="width: 800px;height: 130px;padding: 10px">
    <table cellspacing="8px">
        <tr>
            <td>客户编号：</td>
            <td><input class="easyui-textbox" id="khno" name="khno" editable="false"/></td>
            <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
            <td>客户名称</td>
            <td><input class="easyui-textbox" id="name" name="name" editable="false"/></td>
        </tr>
        <tr>
            <td>客户经理：</td>
            <td><input class="easyui-textbox" id="cusManager" name="cusManager" editable="false"/></td>
            <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
            <td>上次下单时间：</td>
            <td><input class="easyui-textbox" id="lastOrderTime" name="lastOrderTime" editable="false"/></td>
        </tr>
    </table>
</div>

<br/>
<table id="dg" title="客户流失暂缓措施管理" style="width:800px;height:250px"
       toolbar="#dg-tb" idField="id" rownumbers="true" fitColumns="true" singleSelect="true">
    <thead>
    <tr>
        <th field="id" width="50">编号</th>
        <th field="measure" width="300" editor="{type:'textbox',options:{required:true}}">暂缓措施</th>
    </tr>
    </thead>
</table>
<div id="dg-tb">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="javascript:$('#dg').edatagrid('addRow')">添加</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="javascript:$('#dg').edatagrid('destroyRow')">删除</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-save" plain="true" onclick="javascript:$('#dg').edatagrid('saveRow')">保存</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-undo" plain="true" onclick="javascript:$('#dg').edatagrid('cancelRow')">撤销行</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-confirm" plain="true" onclick="javascript:confirmLoss()">确认流失</a>
</div>
</body>
</html>

<script>
    $(function () {
        $.post("${pageContext.request.contextPath}/customerLoss/findById.do",{id:'${param.customerLossId}'},function(result){
            $("#khno").textbox("setValue",result.khno);
            $("#name").textbox("setValue",result.name);
            $("#cusManager").textbox("setValue",result.cusManager);
            $("#lastOrderTime").textbox("setValue",result.lastOrderTime);
        },"json");


        $("#dg").edatagrid({
            url: '${pageContext.request.contextPath}/customerLossReprieve/list.do?saleChanceId=${param.customerLossId}',
            saveUrl: '${pageContext.request.contextPath}/customerLossReprieve/save.do?saleChance.id=${param.customerLossId}',
            updateUrl: '${pageContext.request.contextPath}/customerLossReprieve/save.do?saleChance.id=${param.customerLossId}',
            destroyUrl: '${pageContext.request.contextPath}/customerLossReprieve/delete.do',
            autoSave: true,
            destroyMsg: {
                norecord: {	// when no record is selected
                    title: '警告',
                    msg: '没有数据被选择。'
                },
                confirm: {	// when select a row
                    title: '确认',
                    msg: '确认要删除吗?'
                }
            },
            onSave: function (index, row) {
                // $('#dg').edatagrid('reload');
            },
            onDestroy: function (index, row) {
                // $('#dg').edatagrid('reload');
            },
            onError: function (index, row) {
                // 'isError' 属性设置为 true 的行
                // $('#dg').edatagrid('reload');
            },
            onLoadSuccess: function () {
                //加载成功
            },
        });

    });

    function confirmLoss(){
        $.messager.prompt('系统提示', '请输入流失原因：', function(r){
           if (r != undefined){
                $.post("${pageContext.request.contextPath}/customerLoss/confirmLoss.do",{id:'${param.customerLossId}',lossReason:r},function(result){
                    if(result.success){
                        $.messager.alert("系统提示","执行成功！");
                    }else{
                        $.messager.alert("系统提示","执行失败！");
                    }
                },"json");
            }
        });
    }
</script>
